﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace quanlyktx.quanlyphong
{
    public partial class frmtrangthietbi : Form
    {
        public frmtrangthietbi()
        {
            InitializeComponent();
        }
        ketnoi kn = new ketnoi();
        void load_trangthietbi()
        {
            SqlConnection cn = kn.taokn();
            cn.Open();
            SqlCommand cmd = new SqlCommand("", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            panTrangBi.Controls.Clear();
            SqlDataAdapter da=new SqlDataAdapter(cmd);
            DataTable dt=new DataTable();
            da.Fill(dt);
            int i=0;
            foreach (DataRow row in dt.Rows)
            {
                CheckBox chk = new CheckBox();
                chk.Checked = false;
                chk.Location = new Point(5, i * 25 + 3);
                chk.CheckedChanged += new EventHandler(chk_CheckedChanged);
                chk.Width = 10;
                chk.FlatStyle = FlatStyle.System;
                chk.Name = "chk;" + row["matb"].ToString();
                panTrangBi.Controls.Add(chk);
                Label lbl = new Label();
                lbl.Text = row["TENTHIETBI"].ToString();
                lbl.BorderStyle = BorderStyle.None;
                lbl.Location = new Point(5 + 10 + 5, i * 25 + 5);
                lbl.Width = 150;
                panTrangBi.Controls.Add(lbl);
                NumericUpDown num = new NumericUpDown();
                num.Value = 0;
                num.Minimum = 0;
                num.Maximum = 10;
                num.Location = new Point(5 + 10 + 5 + 150 + 5, i * 25 + 5);
                num.Visible = true;
                num.Enabled = false;
                num.Width = 50;
                panTrangBi.Controls.Add(num);
                chk.Tag = num;
                i++;
                
            }
        }
        private void chk_CheckedChanged(object sender, System.EventArgs e)
        {
            CheckBox chk = sender as CheckBox;
            NumericUpDown num = chk.Tag as NumericUpDown;
            num.Enabled = chk.Checked;
            //cmdSave.Enabled = true;
        }
        private void buttonItem1_Click(object sender, EventArgs e)
        {

        }
    }
}
